#!/bin/sh

if [ "$#" -lt 1 ]; then
	echo "usage: $0 <target_ip[:port]> [src port base] [num connections]"
	exit 1
fi

TARGETHOST="${1%:*}"
TARGETPORT=

test -z "${1##*:*}" && TARGETPORT="${1#*:}"

PORTBASE="$2"
NUMCONN="$3"

if test -z $TARGETHOST; then
	echo "bad host"
	exit 1
fi

test -z $TARGETPORT && TARGETPORT=502

test -z $PORTBASE && PORTBASE=10100

test -z $NUMCONN && NUMCONN=32


for i in $(seq 1 $NUMCONN); do
	tail -f /dev/null | nc -4 -p $(($PORTBASE + $i)) $TARGETHOST $TARGETPORT &
done

